<template>
    
    <!-- 组件的模板 -->
    <div id="items">
        
        <div v-for="item in reportInfo.info"> 
            <div class='border-top' v-if="item.type === 'Location'" :data-id="item.id">
                <div class="comp-wrap addr-per">
                    <div class="weui-cells__title black">{{item.info.title}}<span v-if="item.info.required == 1" class="required_icon"> (必填)</span></div>
                    <div class="feedback-box" @click="feedBack">
                        <img src="../../static/imgs/feedback.png" alt="" class="feedback-icon">
                        <span class="feedback-text">我要反馈</span>
                    </div>
                    <div class="weui-cells__tips">{{item.info.tip}}</div>
                    <div class="weui-cells">
                        <div class="weui-cell padding">
                            <template v-if="pos_addr_name">
                                <div class="addr_name">{{pos_addr_name}}</div>
                            </template>
                            <template v-else>
                                <template v-if="item.info.value.lat && item.info.value.lng">
                                    <template v-if="item.info.value.addr_name == ''">
                                        <div class="addr_name">{{'(' + item.info.value.lng + ',' + item.info.value.lat + ')'}}</div>
                                    </template>
                                    <template v-else>
                                        <div class="addr_name">{{item.info.value.addr_name}}</div>
                                        <div class="addr_detail">{{item.info.value.addr}}</div>
                                    </template>
                                </template>
                                <template v-else>
                                    <div class="addr_name">定位中...</div>
                                </template>                                
                            </template>
                            <div class="location_tip">
                                <p class="error_tips" v-show="isAbnormal"><span class="errorIcon"></span><span class="error_text">地点异常</span></p>
                                <template v-if="!pos_addr_name">
                                    <p class="relacation" v-if="item.info.tune_distance != 0" @click="resetLocation(item.info.tune_distance)">地点微调</p>
                                    <p class="relacation" v-else @click="reLocation">重新定位</p>
                                </template>
                                <template v-else>
                                    <p class="relacation" v-else @click="reLocation">重新定位</p>
                                </template>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class='border-top' v-if="item.type === 'Date'">
                <formdate
                            :title="item.info.title" 
                            :tip="item.info.tip" 
                            :date.sync="item.info.value"
                            :required="item.info.required"
                            :isvalid.sync="item.isValid"
                ></formdate>
            </div>
            <div class='border-top' v-if="item.type === 'SingleText'">
                <formsingle 
                            :title="item.info.title" 
                            :tip="item.info.tip" 
                            :val.sync="item.info.value"
                            :required="item.info.required"
                            :isvalid.sync="item.isValid"
                ></formsingle>
            </div>
            <div class='border-top' v-if="item.type === 'TextArea'">
                <formtextarea 
                            :title="item.info.title" 
                            :tip="item.info.tip" 
                            :val.sync="item.info.value"
                            :required="item.info.required"
                            :isvalid.sync="item.isValid"
                ></formtextarea>
            </div>
            <div class='border-top' v-if="item.type === 'Number'">
                <formnumber
                            :title="item.info.title"
                            :tip="item.info.tip"
                            :val.sync="item.info.value"
                            :required="item.info.required"
                            :isvalid.sync="item.isValid"
                ></formnumber>
            </div>
            <div class='border-top' v-if="item.type === 'Select'">
                <formselect 
                            :title="item.info.title" 
                            :tip="item.info.tip" 
                            :val.sync="item.info.value"
                            :opts="item.info.options"
                            :required="item.info.required"
                            :isvalid.sync="item.isValid"
                ></formselect>
            </div>
            
            <div class='border-top' v-if="item.type === 'Imageview'">
                <div class="comp-wrap">
                    <div class="weui-cells weui-cells_form left_0">
                        <div class="weui-cell" style="padding:0px;">
                            <div class="weui-cell__bd">
                                <div class="weui-uploader">
                                    <div class="bg_f2">
                                        <div class="weui-uploader__hd pad-lr black">
                                            <p class="weui-uploader__title isTitle">{{item.info.title}}
                                                <span v-if="item.info.required == 1 && item.info.check_guide.min != ''" class="required_icon"> (请至少上传{{item.info.check_guide.min}}张图片)</span>
                                                <span v-if="item.info.required == 1 && item.info.check_guide.min == ''" class="required_icon"> (请至少上传1张图片)</span>
                                            </p>
                                            
                                        </div>
                                        <div class="weui-cells__tips pad-left-0 pad-lr">{{item.info.tip}}</div>
                                    </div>
                                    <div class="weui-uploader__bd pad-lr pad-tb" style="position:relative;">
                                        <div class="example_img_div" v-if="item.info.example_img.thumb_url.length">
                                            <p class="tip-txt">示例</p>
                                            <ul>
                                                <li v-for="exampleImg in item.info.example_img.thumb_url">
                                                    <img :src="exampleImg"  alt="" @click="lookBigImg($parent.$index, $index)">
                                                </li>
                                            </ul>
                                        </div>
                                        <div>
                                            <p class="tip-txt">上传</p>
                                            <ul class="weui-uploader__files" id="uploaderFiles">
                                                <li class="weui-uploader__file img" 
                                                    v-for="imgurl in item.info.value.thumb_url" track-by="$index"
                                                    :style="'background-image:url('+'http://image.doumi.com/'+imgurl+')'"
                                                    @click="pictureOperationDialog($parent.$index, $index)"
                                                    >
                                                </li>
                                            </ul>
                                        </div>
                                        
                                        <div class="weui-uploader__input-box">
                                            <input id="uploaderInput" class="weui-uploader__input" type="" readonly @click="selectImage($index,item.info.can_choose_picture)" />
                                        </div>
                                        <!-- <div class="weui-uploader__info img_cont">{{item.info.value.length}}/20</div> -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="kong_div"></div>
    <!-- 根据打卡结果展示不同的提示 -->
    <div class="weui-mask" v-show="isShowTip"></div>
    <div class="popup-tip" v-show="isShowTip">
        <div class="content com-border-bottom b_bottom">
            <img class="icon icon_1" v-show="tip_img1" src="../../static/imgs/tip/i1.png" alt="">
            <img class="icon icon_1" v-show="tip_img2" src="../../static/imgs/tip/i2.png" alt="">
            <img class="icon icon_3" v-show="tip_img3" src="../../static/imgs/tip/i3.png" alt="">
            <p class="tip">{{tipMsg}}</p>
            <p class="tip_detail">{{tipdetailMsg}}</p> 
            <div class="text-wrap com-border-outside" v-show="tip_img2 || tip_img3">
                <textarea class="text" placeholder="请输入异常原因(非必填)" v-model="reason">{{reason}}</textarea>
            </div>            
        </div>        
        <div class="btn-box my_click" @click="confirm_tip">
            <a href="javascript:;">确定</a>            
        </div>
    </div>
    <!-- 保险浮层部分 -->
    <template v-if="insurance">
        <div class="weui-mask" style="background: rgba(0, 0, 0, 0.75);"></div>
        <div class="popup_insurance">
            <p class="tip">务必输入真实姓名和身份证，否则保险无法生效</p>
            <div class="form-wrap">
                <div class="item">
                    <input type="text" name="" placeholder="真实姓名" v-model="realName">
                </div>
                <div class="item">
                    <input type="text" name="" placeholder="身份证号码" v-model="identityCode">
                </div>            
                <a class="button" href="javascript:;" @click="receiveInsurance">领取保险</a>
                <!-- <p class="link"><a href="javascript:;" @click="latterReceive">稍后领取</a></p> -->
            </div>
        </div>
    </template>
    
    <template v-if="insurance_success">
        <div class="weui-mask" style="background: rgba(0, 0, 0, 0.75);" @click="receiveSuccess"></div>
        <div class="popup_insurance_success" @click="receiveSuccess">
            <img class="icon_insurance" src="../../static/imgs/icon_insurance.png" alt="">
            <span class="tip">领取成功!</span>
        </div>
    </template>
</template>

<script>
    let ajaxEnd = true
    let url = ''
    let coordinate = ''
    let coordinate2 = ''//第一次定位的经纬度 地点微调时使用
    let ajaxDate = {}
    let form_data = []
    let confirm_attendance_id = ''
    let phone_model = ''
    let device_code = ''
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    import widget from 'gapi/widget.js'
    import clientUi from 'gapi/clientUi.js'
    import * as util from 'js/util.js'
    import commonPage from 'clientApi/commonPage.js'
    // import location from 'clientApi/location.js'
    import userCenterApi from 'clientApi/userCenterApi'
    import cache from 'gapi/cache.js'
    import clientInfo from 'gapi/clientInfo'
    import KCApiApp from 'clientApi/KCApiApp.js'
    import teamApi from 'clientApi/teamApi.js'

    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */
    import Formsingle from 'components/Formsingle/Formsingle'
    import Formtextarea from 'components/Formtextarea/Formtextarea'
    import Formnumber from 'components/Formnumber/Formnumber'
    import Formselect from 'components/Formselect/Formselect'
    import Formdate from 'components/Formdate/Formdate'
    import Location from 'components/Location/Location'
    import { getLoc } from 'components/Location/LocationGetters'
    import Imageview from 'components/Imageview/Imageview'
    import { getImageArray } from 'components/Imageview/ImageviewGetters'

    /**
     *  组件实例对象
     */
    export default {
        components: {
            Formsingle,
            Formtextarea,
            Formnumber,
            Formselect,
            Formdate,
            Location,
            Imageview
        },
        data: function(){
            return{
                isMoreClick:true,
                isAgainSubmint:true,
                isGoBack:true,
                webViewID:'',
                isShowTip:false,
                tipMsg:'',
                tip_img1:false,
                tip_img2:false,
                tip_img3:false,
                reason:'',
                pos_addr_name:'',
                isAbnormal: false,//定位地点是否异常
                imgDate:{
                    pos:'',
                    pos_name: ''
                },
                pageDate:{
                    team_id: 0,
                    project_id: 0,
                    user_id:'',
                    form_id: 0,
                    user_name:'',
                    examples_img_url: [],
                    example_img_thumb_url: [],
                    time_id: 0,
                    attendance_id: 0,
                    task_id: 0,
                    name: '',
                    form_data_id:'',
                    require_field: {},
                    schedule_id: 0,
                    task_id_yesterday: 0,
                    cross_attend: 0,
                    cross: 0,
                },
                reportInfo: {
                    info: []
                },
                require_field_formid:'',
                par_index: 0,
                allow_album: false,//是否允许选择相册图片
                /*保险部分*/
                insurance: false,//是否弹出领取保险
                insurance_success: false,//领取成功
                identityCode: '',//领取保险人身份证号码
                realName: '',//领取保险人填写姓名
                mobile: 0,//领取保险时带来的手机号
                user_id:'',
                taskId:'',
                failNum: 0,//记录定位失败次数
                tipdetailMsg: '',
            }
        },
        computed:{
            watermark(){
                return this.allow_album ? 1 : 0
            }
        },
        vuex: {
            getters: {
                getLoc,
                getImageArray
            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
                userCenterApi.getDeviceInfo(function(info){
                    if(info){
                        phone_model = info.phone_model
                        device_code = info.device_code
                        
                    }
                })
                this.type = util.getUrddataString('type') || 1

                if(this.type == 1){
                    cache.getCache('KaoqinEditInfo', (data)=>{                        
                        console.log("考勤"+JSON.stringify(data))
                        if(data.attendance.cross_attend == 1){
                            this.reportInfo.info = data.extra_info.require_field_yesterday
                            this.taskId = data.extra_info.task_id_yesterday
                        }else{
                            this.reportInfo.info = data.extra_info.require_field
                            this.taskId = data.extra_info.task_id

                        }
                        this.pageDate.team_id = data.team_id
                        this.pageDate.user_id = data.user_id
                        this.pageDate.project_id = data.project_id
                        this.pageDate.task_id = data.extra_info.task_id
                        this.pageDate.time_id = data.attendance.time_id
                        this.pageDate.attendance_id = data.attendance.attendance_id
                        this.pageDate.form_data_id = data.attendance.form_data_id
                        this.pageDate.require_field = data.extra_info.require_field
                        this.pageDate.user_name = data.extra_info.user_name
                        this.pageDate.schedule_id = data.attendance.schedule_id
                        this.pageDate.task_id_yesterday = data.extra_info.task_id_yesterday
                        this.pageDate.cross_attend = data.attendance.cross_attend
                        this.pageDate.cross = data.attendance.cross

                        //定位
                        this.reLocation()
                        //获取保险信息
                        this.getInsuranceInfo()
                        
                    })
                    
                    cache.getMemoryCache('webViewID', (data)=>{
                        this.webViewID = data.webViewID
                    })
                }else{
                    //签到
                    this.pageDate.team_id = util.getUrddataString('team_id')
                    this.pageDate.project_id = util.getUrddataString('project_id')
                    this.pageDate.name = util.getUrddataString('user_name')
                    // 设置拍照水印信息
                    this.imgDate.name = this.pageDate.name
                    //获取签到设置信息
                    this.getSetSignInfo()
                    //获取保险信息
                    this.getInsuranceInfo()
                }  

               
            },
            //获取签到设置信息
            getSetSignInfo(){
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/sign/project/setting',
                    type:'GET',
                    data: {
                        team_id: this.pageDate.team_id,
                        project_id: this.pageDate.project_id
                    },
                    success: (res) => {
                        console.log("填写信息"+JSON.stringify(res))
                        if(res&&res.errno == 0){
                            this.reportInfo.info = res.data.setting_data.require_field
                            this.require_field_formid = res.data.setting_data.require_field_formid
                            this.pageDate.user_name = res.data.user_name
                            //定位
                            this.reLocation()
                        }else{
                            widget.toast(res.errmsg)
                            commonPage.loadPageStatus('loadSuccess')
                        }
                    },
                    error: (xhr, error) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            //定位当前位置
            reLocation (){
                commonPage.loadPageStatus('loading')
                util.requestPOI((data)=>{
                    if(data&&data.lon != undefined&&data.address){
                        this.pos_addr_name = ''
                        commonPage.loadPageStatus('loading')
                        coordinate = data.lon+','+data.lat
                        coordinate2 = coordinate2 ? coordinate2 : data.lon+','+data.lat
                        this.reportInfo.info.forEach( (item) => {
                            if(item.type == 'Location'){
                                item.title = data.name
                                item.info.value = {
                                    "lat": data.lat,
                                    "lng": data.lon,
                                    "addr": data.address,
                                    'addr_name':data.name
                                }
                                item.map_type=1
                                this.imgDate.pos = data.address
                                this.imgDate.pos_name = data.name
                            }

                        })
                        commonPage.loadPageStatus('loadSuccess')
                        
                        if(this.type == 1){
                            //检测定位点是否在微调范围内
                            this.checkLocation()
                        }
                        
                    }else if(data&&data.lon != undefined && data.address == '' && data.name == ''){
                        this.pos_addr_name = ''
                        commonPage.loadPageStatus('loading')
                        coordinate = data.lon+','+data.lat
                        coordinate2 = coordinate2 ? coordinate2 : data.lon+','+data.lat
                        this.reportInfo.info.forEach( (item) => {
                            if(item.type == 'Location'){
                                item.title = data.name
                                item.info.value = {
                                    "lat": data.lat,
                                    "lng": data.lon,
                                    "addr": data.address,
                                    'addr_name':data.name
                                }
                                this.imgDate.pos = data.address
                                this.imgDate.pos_name = data.name
                            }

                        })
                        commonPage.loadPageStatus('loadSuccess')
                        
                        if(this.type == 1){
                            //检测定位点是否在微调范围内
                            this.checkLocation()
                        }
                    }else{

                        KCApiApp.showLocationAuthAlertDialog()                       
                        
                        this.pos_addr_name = '定位失败...'
                        commonPage.loadPageStatus('loadSuccess')
                        if(data){
                            widget.toast(data.error_msg)
                        }else{
                            widget.toast('定位失败，请检查网络')
                        }
                        
                        
                    }
                }) 
            },
            // 地点微调
            resetLocation(tune_distance){
                clientInfo.getNetworkType((data) => {
                    if(data.network == 'invalid'){
                        widget.toast("网络连接失败，请检查网络")
                        return
                    }
                    //埋点
                    let statisticsLog_data = {
                        event_id: '填写信息-地点微调',
                        // event_label: data.event_label,(预留，现在不用传此参数)
                        event_param: {
                            ca_from: 'modify',
                            project_id: this.pageDate.project_id,
                        }
                    }
                    // alert(JSON.stringify(statisticsLog_data))
                    KCApiApp.statisticsLog(statisticsLog_data)
                    
                    console.log(tune_distance)
                    let encodeStr = encodeURIComponent(`tune_distance=${tune_distance}&address_lat=${coordinate2.split(',')[1]}&address_lng=${coordinate2.split(',')[0]}`)
                    window.location.href = `dmsaas://ResetLocation?urdData=${encodeStr}`
                })
            },
            //检测定位点是否在微调范围内
            checkLocation(){
                if(!coordinate){
                    widget.toast('定位失败,请稍后重试')
                    return
                }
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/attendance/position/check',
                    type:'GET',
                    data: {
                        team_id: this.pageDate.team_id,
                        project_id: this.pageDate.project_id,
                        coordinate: coordinate,
                        task_id: this.taskId
                    },
                    success: (res) => {
                        console.log(JSON.stringify(res))
                        commonPage.loadPageStatus('loadSuccess')
                        if(res&&res.errno==0){
                            if(res.data.valid == 1){
                                this.isAbnormal = false
                            }else{
                                this.isAbnormal = true
                            }
                        }else{
                             widget.toast(res.errmsg)
                        }
                    },
                    error: (xhr, error) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            //选择上传照片
            selectImage (index,can_choose_picture){
                if(this.reportInfo.info[index].info.value.url.length < 20){  
                    /*can_choose_picture == 1 选择相册；can_choose_picture == 0 水印相机*/
                    if(can_choose_picture == 1){ /*选择相册*/
                        this.allow_album = true
                        clientUi.selectAndUploadImage((data) => {
                            console.log(data)
                            if(data.status == 1){
                                this.reportInfo.info[index].info.value.url.push(util.baseImageDomain + data.info[0].url)
                                this.reportInfo.info[index].info.value.thumb_url.push(data.imageURL)
                            }
                            
                        })
                    }else{  /*调起水印相机*/
                        this.allow_album = false
                        clientUi.invokeCamera((data) => {
                            console.log(data)
                            // alert(JSON.stringify(data))
                            if(data.status == 1){
                                this.reportInfo.info[index].info.value.url.push(util.baseImageDomain+data.info[0].url)
                                this.reportInfo.info[index].info.value.thumb_url.push(data.info[0].thumbUrl) 
                            }
                        }) 
                        // let date = new Date()
                        // let year = date.getFullYear()
                        // let month = (date.getMonth()+1)<10?'0'+(date.getMonth()+1):(date.getMonth()+1)
                        // let day = date.getDate()<10?'0'+date.getDate():date.getDate()
                        // let hour = date.getHours()<10?'0'+date.getHours():date.getHours()
                        // let minutes = date.getMinutes()<10?'0'+date.getMinutes():date.getMinutes()
                        // this.imgDate.date = year+"-"+month+"-"+day
                        // this.imgDate.time = hour+":"+minutes
                        // this.imgDate.logo = '灵云'
                        // this.imgDate.name = this.pageDate.user_name
                        // commonPage.loadPageStatus('loading')
                        // KCApiApp.takePicture(this.imgDate, (data) => {
                        //     console.log(data)
                        //     commonPage.loadPageStatus('loadSuccess')
                        //     if(data!=0){
                        //         if(data.error==0){
                        //             this.reportInfo.info[index].info.value.url.push(util.baseImageDomain+data.info[0].url)
                        //             this.reportInfo.info[index].info.value.thumb_url.push(data.info[0].thumbUrl)
                        //         }else{
                        //             widget.toast('上传图片异常')
                        //         }
                        //     }
                        // })
                    }
                }else{
                    widget.toast('已达上传上限')
                }
            },
            //图片--查看大图及删除
            pictureOperationDialog (par_index, index){
                clientUi.pictureOperationDialog('title', this.reportInfo.info[par_index].info.value.url, index, () => {
                    this.reportInfo.info[par_index].info.value.url.splice(index, 1)
                    this.reportInfo.info[par_index].info.value.thumb_url.splice(index, 1)
                })
            },
            //缩略图查看大图
            lookBigImg(par_index, index){
                let title = '';
                let newImgArr = []
                let oldImgArr = this.reportInfo.info[par_index].info.example_img.url
                oldImgArr.forEach( (item) => {
                    newImgArr.push(util.baseImageDomain + item)
                })

                clientUi.bigPicturePreview(title, newImgArr, index)
            },
            //提交
            submit (){
                console.log(this.isAgainSubmint)
                let isAllValid = this.valiDate();
                form_data = []
                if(isAllValid){
                    this.reportInfo.info.forEach( (item) => {
                        let _url = []
                        let _thumb_url = []
                        if(item.type == 'Imageview'){
                            item.info.value.url.forEach( (urlItem) => {
                                _url.push(urlItem.replace(util.baseImageDomain,''))
                            })
                            item.info.value.thumb_url.forEach( (thumbItem) => {
                                _thumb_url.push(thumbItem)
                            })
                            item.info.value = {
                                url:_url,
                                thumb_url:_thumb_url
                            }
                        }
                        let locStr = {
                            id:item.id,
                            type:item.type,
                            value:item.info.value
                        }
                        form_data.push(locStr)
                    })
                    if(this.type == 1){
                        ajaxDate = {
                            team_id: this.pageDate.team_id,
                            project_id: this.pageDate.project_id,
                            task_id: this.pageDate.task_id,
                            time_id:this.pageDate.time_id,
                            // coordinate: coordinate,
                            form_data:form_data,
                            watermark:1,
                            schedule_id:this.pageDate.schedule_id,
                            task_id_yesterday: this.pageDate.task_id_yesterday,
                            cross_attend: this.pageDate.cross_attend,
                            cross: this.pageDate.cross,
                            phone_model: phone_model,
                            device_code: device_code
                        }
                        if(this.pageDate.attendance_id){
                            ajaxDate.attendance_id = this.pageDate.attendance_id
                            ajaxDate.form_data_id = this.pageDate.form_data_id
                            url="/attendance/attendance/update"
                        }else{
                            url="/attendance/attendance/add"
                        }
                    }else if(this.type == 2){

                        ajaxDate = {
                            team_id: this.pageDate.team_id,
                            project_id: this.pageDate.project_id,
                            require_field_formid:this.require_field_formid,
                            form_data:form_data,
                            watermark:1,
                            phone_model: phone_model,
                            device_code: device_code
                        }
                        url = '/sign/user/submit'
                    }
                    console.log("入参"+JSON.stringify(ajaxDate))
                    //发送网络请求
                    if(this.isAgainSubmint == true){
                        if(this.isMoreClick == true){
                            this.isMoreClick = false
                            util.ajax({
                                url: url,
                                type:'POST',
                                data: ajaxDate,
                                success: (res) => {
                                    console.log(JSON.stringify(res))
                                     if(res&&res.errno==0){
                                        this.isAgainSubmint = false
                                        this.isGoBack = false
                                        confirm_attendance_id = res.data.attendance_id
                                        if(this.type == 1){
                                            let status = res.data.status
                                            let status_code = res.data.status_code
                                            this.isShowTip = true
                                            if(status_code == 0){
                                                this.tipMsg = status
                                                this.tip_img1 = true
                                            }else if(status_code == 2){
                                                this.tipMsg = '地点异常'
                                                this.tip_img2 = true
                                            }else{
                                                this.tipMsg = status
                                                this.tipdetailMsg = res.data.time_tip
                                                this.tip_img3 = true
                                            }
                                        }else{
                                            widget.toast('上报位置成功')
                                            setInterval(() => {           
                                                commonPage.goBack(1)
                                            }, 2000)
                                        }
                                        
                                    }else if(res.errmsg){
                                        this.isAgainSubmint = true
                                        this.isGoBack = true
                                        this.isMoreClick = true
                                         widget.toast(res.errmsg)
                                    }else{
                                        widget.toast('数据获取失败')
                                        this.isAgainSubmint = true
                                        this.isGoBack = true
                                        this.isMoreClick = true
                                    }
                                },
                                error: (xhr, error) => {
                                    widget.toast('服务器异常')
                                    this.isAgainSubmint = true
                                    this.isGoBack = true
                                    this.isMoreClick = true
                                },
                                noNetwork: () => {
                                    // 无网络的回调
                                    widget.toast('网络连接失败，请检查网络')
                                    this.isAgainSubmint = true
                                    this.isGoBack = true
                                    this.isMoreClick = true
                                }
                            })
                        }
                    }
                }
            },
            //表单验证
            valiDate (){
                let isAllValid = false;
                let date = {}
                let form_data = []
                for(let obj of this.reportInfo.info){
                    if(obj.type == 'Number' && obj.info.value && isNaN(obj.info.value)){
                        widget.toast(obj.info.title + ' 只允许输入纯数字!')
                        return
                    }
                    if(obj.info.required == 1){
                        if(obj.type == 'Location'){
                            if(!obj.info.value.addr){
                                widget.toast(obj.info.title + ' 为必填项!')
                                isAllValid = false;
                                break;
                            }else if(!obj.info.value.lat || !obj.info.value.lng){
                                widget.toast('定位失败,请稍后重试')
                                isAllValid = false;
                                break;
                            }else{
                                isAllValid = true
                            }
                        }else if(obj.type == "Imageview"){
                            if(!obj.info.value.thumb_url.length){
                                widget.toast(obj.info.title + ' 为必填项!')
                                isAllValid = false;
                                break;
                            }else if(obj.info.value.thumb_url.length < obj.info.check_guide.min){
                                widget.toast('请至少上传' + obj.info.check_guide.min + '张图片')
                                isAllValid = false;
                                break;
                            }else{
                                isAllValid = true
                            }
                        }else{
                            if(!(obj.info.value && obj.info.value.length)){
                                widget.toast(obj.info.title + ' 为必填项!')
                                isAllValid = false;
                                break;
                            }else{
                                isAllValid = true
                            }
                        }
                        
                    }else{
                        isAllValid = true
                    }
                }
                return isAllValid;   
            },
            //打卡弹层--确认
            confirm_tip (){
                let _data = {
                    team_id:this.pageDate.team_id,
                    project_id:this.pageDate.project_id,
                    attendance_id:this.pageDate.attendance_id == 0 ? confirm_attendance_id : this.pageDate.attendance_id,
                    reason:this.reason
                }
                console.log(_data)
                if(this.tip_img2 || this.tip_img3){
                    util.ajax({
                        url: '/attendance/abnormal_reason/add',
                        type:'GET',
                        data: _data,
                        success: (res) => {
                            console.log(res)
                            if(res&&res.errno==0){
                                commonPage.goBack(1,{'key':'yy_kqeditinfo'}, this.webViewID)
                            }else if(res.errmsg){
                                 widget.toast(res.errmsg)
                            }else{
                                widget.toast('数据获取失败')
                            }
                        },
                        error: (xhr, error) => {
                            widget.toast('服务器异常')
                        },
                        noNetwork: () => {
                            // 无网络的回调
                            widget.toast('网络连接失败，请检查网络')
                        }
                    })
                }else{
                    commonPage.goBack(1,{'key':'yy_kqeditinfo'}, this.webViewID)
                }
            },
/*************************************关于保险部门****************************************/
            //获取保险信息
            getInsuranceInfo(){
                // 判断所在团队是否有保险应用  之后再掉完善资料接口 
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/application/vision/area',
                    type: 'GET',
                    data: {
                        team_id: this.pageDate.team_id,
                        project_id: this.pageDate.project_id
                    },
                    timeout: 10000,
                    success: (obj) => {
                        console.log(obj)
                        // widget.toast(JSON.stringify(obj))
                        commonPage.loadPageStatus('loadSuccess')
                        if(obj.errno == 0){
                            obj.data.result.forEach((item) => {
                                if(item.app_id == 5){
                                    //是否购买保险
                                    //判断是否领取保险
                                    commonPage.loadPageStatus('loading')
                                    util.ajax({
                                        url: '/insurance/user_info/get',
                                        type: 'GET',
                                        data: {
                                            team_id: this.pageDate.team_id,
                                            project_id: this.pageDate.project_id,
                                            type: 2//区分是考勤(1)还是签到(2)
                                        },
                                        timeout: 10000,
                                        success: (res) => {
                                            console.log(res)
                                            commonPage.loadPageStatus('loadSuccess')
                                            if(res.errno == 0){
                                                if(res.data[0].status == 1){
                                                    this.insurance = true
                                                    this.identityCode = res.data[0].info.id_number ? res.data[0].info.id_number : ''
                                                    this.realName = res.data[0].info.name ? res.data[0].info.name : ''
                                                    this.user_id = res.data[0].info.user_id
                                                    this.mobile = res.data[0].info.mobile
                                                    if(this.insurance){
                                                        this.isAgainSubmint = false
                                                        this.isGoBack = true
                                                    }  
                                                }
                                            }else{
                                                widget.toast(res.errmsg)
                                            }
                                        },
                                        error: (xhr, status) => {
                                            commonPage.loadPageStatus('loadSuccess')
                                            widget.toast('服务器异常')
                                            // error
                                        },
                                        noNetwork: () => {
                                            // 无网络的回调
                                            commonPage.loadPageStatus('loadSuccess')
                                            widget.toast('网络连接失败，请检查网络')
                                        }
                                    })
                                }
                            })
                        }else{
                            widget.toast(obj.errmsg)
                        }
                    },
                    error: (xhr, status) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                        // error
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })   
            },
             //领取保险
            receiveInsurance(){
                //校验姓名
                let reg = /[^\u4E00-\u9FA5\·]/;
                if(!this.realName){
                    widget.toast('请输入您的真实姓名')
                    return
                }else if( reg.test(this.realName)){
                    widget.toast("请输入真实姓名，否则保险无法生效");
                    return
                }
                if(!this.identityCode){
                    widget.toast('请输入身份证号码')
                    return
                }
                //校验身份证
                // if(!this.identityCodeValid(this.identityCode)){
                //     widget.toast('身份证号格式错误，请重新输入')
                //     return
                // }
                let _data = {
                        team_id: this.pageDate.team_id,
                        project_id: this.pageDate.project_id,
                        info: {
                            "user_id": this.user_id,
                            "id_number": this.identityCode,
                            "name": this.realName,
                            "mobile": this.mobile
                        }
                    }
                console.log(_data)
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/insurance/user_info/set',
                    type: 'POST',
                    data:_data,
                    timeout: 10000,
                    success: (data) => {
                        console.log(data)
                        commonPage.loadPageStatus('loadSuccess')
                        if(data.errno == 0){
                            //领取保险成功后
                            this.insurance = false
                            this.insurance_success = true
                            if(this.insurance_success){
                                this.isAgainSubmint = false
                                this.isGoBack = true
                            } 
                        }else{
                            widget.toast(data.errmsg)
                        }
                    },
                    error: (xhr, status) => {
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('服务器异常')
                    },
                    noNetwork: () => {
                        // 无网络的回调
                        commonPage.loadPageStatus('loadSuccess')
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
             //稍后领取
            latterReceive(){
                this.insurance = false
                if(this.insurance == false){
                    this.isAgainSubmint = true
                    this.isGoBack = true
                } 
            },
            //领取成功
            receiveSuccess(){
                this.insurance_success = false
                if(this.insurance_success == false){
                    this.isAgainSubmint = true
                    this.isGoBack = true
                } 
            },
            //校验身份证
            identityCodeValid(code){
                let city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
                let tip = "";
                let pass= true;
                
                if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
                    tip = "身份证号格式错误";
                    pass = false;
                }else if(!city[code.substr(0,2)]){
                    tip = "地址编码错误";
                    pass = false;
                }else{
                    //18位身份证需要验证最后一位校验位
                    if(code.length == 18){
                        code = code.split('');
                        if(code[17] === 'x')code[17]='X'
                        //∑(ai×Wi)(mod 11)
                        //加权因子
                        let factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
                        //校验位
                        let parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
                        let sum = 0;
                        let ai = 0;
                        let wi = 0;
                        for (let i = 0; i < 17; i++)
                        {
                            ai = code[i];
                            wi = factor[i];
                            sum += ai * wi;
                        }
                        let last = parity[sum % 11];
                        if(parity[sum % 11] != code[17]){
                            tip = "校验位错误";
                            pass =false;
                        }
                    }
                }
                // if(!pass) alert(tip);
                return pass;
            },
            //反馈入口
            feedBack (){
                teamApi.showFeedback()
            }
        },
        created(){
            this.init();
            /**
             * 设置提交按钮
             * @type {String}
             */
            commonPage.updateTitleBar({
                backAction: 'gotoback',
                leftAction: 'gotoback',
                rightDisplay: true,
                rightText: '提交',
                rightAction: 'doSubmit'
            })
          
            window.gotoback = () => {
                if(this.isGoBack == true){
                    commonPage.goBack(1)
                }
                
            }
            
            window.doSubmit = this.submit 
            window.loadData = (data) => {
                if(data&&data !== undefined){
                    console.log(data)
                    if(data.key == "position"){
                        coordinate = data.value.coordinate
                        this.reportInfo.info.forEach( (item) => {
                            console.log(item)
                            if(item.type == 'Location'){
                                item.info.value = {}
                                item.info.value = {
                                    "lat": coordinate.split(',')[1],
                                    "lng": coordinate.split(',')[0],
                                    "addr": data.value.address,
                                    'addr_name': data.value.name
                                }
                                item.map_type=1
                                this.imgDate.pos = data.value.address
                                this.imgDate.pos_name = data.value.name
                            }
                        })
                        if(this.type == 1){
                            //检测定位地点是否在微调范围内
                            this.checkLocation()
                        }
                    }
                }
            }
        }
        
    }

    
</script>

<!-- CSS 样式 -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<!-- <style src="../../static/css/common.css"></style> -->
<style type="text/css">
    html {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    }
    html body{
        /*background-color: #fff;*/
        background-color: #f2f2f2;
    }
    div.weui-cells{
        margin-top:0px;
        font-size: 15px;
        
    }
    div.weui-cell{
        padding-top: 14px;
        padding-bottom: 14px;
    }
    div.comp-wrap{
        background-color: #f2f2f2;
        /*background-color: #fff;*/
        padding-top: 0.1px;
    }
    div.border-top{
        /*border-top:12px solid #f2f2f2;*/
        /*position: relative;*/
        /*padding:0.1px;*/
    }
    #items div:first-child div.border-top{
        border-top: 0;
    }
    div.black{
        color: rgb(51,51,51);
        font-size: 16px;
        margin-bottom: 0px;
        margin-top: 16px;
        line-height: 1.375;
    }
    div.border-top div.weui-cells__tips{
        margin-bottom: 6px;
        color: rgb(102,102,102);
        font-size: 14px;
        margin-top: 0;
        line-height: 1.375;
    }
    li.img{
        overflow: hidden;
        width:60px;
        height:60px;
        /*box-sizing: border-box;
        margin-right:0;
        padding-right: 9px;*/
        margin-right: 8px;
        margin-bottom: 8px;
    }
    li.img img{
        /*width:100%;*/
        width: 60px;
        /*height: 60px;*/
    }
    div.weui-uploader__input-box{
        width:60px;
        height:60px;
        margin-right: 8px;
        margin-bottom: 8px;
    }
    div.pad-left-0{
        padding-left: 0;
    }
    div.pad-lr{
        padding:0px 12px;
    }
    div.pad-tb{
        padding:24px 12px 32px;
    }
    div.weui-uploader__bd{
        margin:0;
    }
    div.bg_color{
        background-color: #f2f2f2;
        margin:0;
        /*margin-top:7px;*/
        /*padding-top: 18px;
        padding-bottom: 4px;*/
        padding:10px 12px;
        line-height: 1.3;
        text-align: center;
    }
    div.weui-textarea-counter,div.weui-uploader__info{
        font-size: 12px;
        color: #999;
    }
    div.weui-cells:before{
        border-top: 1px solid #e5e5e5;
        /*left:12px;*/
        left:0px;
    }
    div.weui-cells.left_0:before{
        left:0;
    }
    div.weui-cells:after{
        border-bottom: 1px solid #e5e5e5;
    }
    div.weui-cell a.weui-btn_default{
        background-color: #fff;
        border:none;
        color:#4499ff;
        padding-right: 4px;
    }
    div.weui-cell a.weui-btn_default:active{
        background-color: #fff;
        opacity: 0.5;
        color: #4499ff;
    }    
    .padding-12{
        padding-left: 12px;
        font-size: 14px;
    }
    .isTip{
        color: #ccc;
    }
    p.weui-uploader__title{
        color:rgb(51,51,51);
    }
    p.isTitle{
        font-size: 16px;
    }
    input.weui-input{
        font-size: 16px;
    }
    
    input{
        -webkit-appearance: none;
    }
    textarea.weui-textarea{
        font-size: 16px;
    }
    div.isValue p{
        font-size: 16px;
    }
    div.bg_f2{
        background-color: #f2f2f2;
        padding:0.1px;
    }
    div.img_cont{
        position: absolute;
        right:12px;
        bottom:12px;
        color: rgb(153,153,153);
        font-size: 14px;
    }
    span.required_icon{
        /*display: inline-block;
        width:7px;
        height:7px;
        margin-left: 5px;
        margin-bottom: 2px;
        background-image: url(../../static/imgs/required.png);*/
        font-size: 14px;
        color: rgb(153,153,153);
    }
    .weui-btn:after{
        border: none;
    }
    .bg_sprite{
        display: inline-block;
        background-image: url(../../static/imgs/sprite.png);
        background-repeat: no-repeat;
        -webkit-background-size: 250px auto;
        background-size: 250px auto;
    }
    .error_tip{
       font-size: 14px;
       color: rgb(243,131,85);
       padding-left: 30px;
       margin-top: 2px;
       position: relative;
    }
    .error_tip .error_icon{
        background-position: 0px -510px;
        position: absolute;
        width: 12px;
        height: 20px;
        left: 12px;
        top: 0px;
        z-index: 1;
    }
    .example_img_div{
        overflow: hidden;
    }
    .example_img_div li{
        float: left;
        width: 60px;
        height: 60px;
        margin-right: 10px;
        margin-bottom: 10px;
        list-style: none;
    }
    .example_img_div img{
        overflow: hidden;
        width: 60px;
        height: 60px;
    }
    .tip-txt{
        font-size: 14px;
        color: rgb(102,102,102);
        margin-bottom: 10px;
    }

    /* 考勤提示框 */
    .popup-tip {
        position: fixed;
        z-index: 9999;
        width: 270px;
        background: #f2f2f2;
        left: 50%;
        top: 50%;
        -webkit-transform: translate3d(-50%, -50%, 0);
        transform: translate3d(-50%, -50%, 0);
        border-radius: 12px;
    }
    .popup-tip .content {
        padding: 30px 16px 20px;
        background: url(../../static/imgs/tip/bg.png) no-repeat;
        -webkit-background-size: 270px auto;
        background-size: 270px auto;
    }
    .popup-tip .icon {
        display: block;
        margin: 0 auto 12px;    
    }
    .popup-tip .icon_1 {
        width: 124px;
    }
    .popup-tip .icon_3 {
        width: 95px;
    }
    .popup-tip .tip {
        font-size: 16px;
        line-height: 22px;
        text-align: center;
        margin-bottom: 4px;
    }
    .popup-tip .btn-box {
       /* display: -webkit-flex;
        display: flex;*/
    }
    .popup-tip .btn-box a {
        /*flex: 1;*/
        line-height: 44px;
        color: #fa0;
        font-size: 17px;
        /*-webkit-flex: 1;*/
        text-align: center;    
        display: block;
        margin: 0 auto;

    }
    .popup-tip .text-wrap {
        margin-top: 18px;
        padding: 1px;
    }
    .popup-tip .text {  
        width: 100%;
        box-sizing: border-box;
        border: none;
        height: 70px;
        padding: 10px;
        border-radius: 6px;
        display: block;
        position: relative;
        z-index: 1;
        font-size: 14px;
        line-height: 20px;
    }
    .popup-tip .text-wrap::after {
        border-radius: 6px;
    }
    .my_click:active {
        background: #e5e5e5;
        border-radius: 12px;
    }
    .b_bottom::after {
        content: "";
        position: absolute;
        width: 100%;
        height: 1px;
        background-color: rgb(229, 229, 229);
        left: 0;
        -webkit-transform: scale3d(1, 0.5, 1);
        transform: scale3d(1, 0.5, 1);
        z-index: 9;
    }
    .b_bottom::after {
        bottom: 44px;
        -webkit-transform-origin: 0 100%;
        transform-origin: 0 100%;
    }
    /* insurance */
    .popup_insurance {
        position: absolute;
        width: 281px;
        height: 413px;
        padding: 140px 12px 0;
        box-sizing: border-box;
        background: url(../../static/imgs/bg_insurance_2.png) no-repeat center top;
        -webkit-background-size: cover;
        background-size: cover;
        left: 50%;
        top: 50%;
        /* -webkit-transform: translate3d(-50%, -50%, 0);
        transform: translate3d(-50%, -50%, 0); */
        margin: -206px 0 0 -140px;
        z-index: 9999;
        border-radius: 12px;
    }
    .popup_insurance .tip {
        color: #666;
        margin: 0 12px 12px;
        text-align: center;
    }
    .form-wrap .item {
        height: 48px;
        background: #fff;   
        border-radius: 3px;
        display: -webkit-flex;
        display: flex;  
        margin-bottom: 12px;
        position: relative;
        overflow: hidden;
    }
    .form-wrap .item::before {
        content: "";
        width: 200%;
        height: 200%;
        border: 1px solid rgb(220, 222, 227);
        box-sizing: border-box;
        border-radius: 6px;
        position: absolute;
        left: 0;
        top: 0;
        -webkit-transform: scale(0.5);
        transform: scale(0.5);
        -webkit-transform-origin: 0 0;
        transform-origin: 0 0;
    }
    .form-wrap input {
        border: none;
        -webkit-flex: 1;
        flex: 1;
        font-size: 14px;
        padding: 0 12px;
        position: relative;
        background: transparent;
    }
    .form-wrap .button {
        width: 168px;
        height: 42px;
        line-height: 42px;
        text-align: center;
        display: block;
        margin: 22px auto 0;
        background: rgb(248, 103, 56);
        border: 1px solid rgb(220, 81, 13);
        border-radius: 21px;
        box-shadow: 0 3px 8px rgb(247, 169, 111);
        font-size: 17px;
        color: rgb(255, 240, 222);
    }
    .form-wrap .button:active {
        background: #DC510D;
    }
    .form-wrap ::-webkit-input-placeholder {
        color: rgb(187, 187, 187);
    }
    .popup_insurance .link {
        text-align: center; 
        line-height: 20px;
        margin-top: 12px;
    }
    .popup_insurance .link a {
        color: rgb(223, 113, 105);
    }
    .popup_insurance_success {
        position: absolute;
        z-index: 9999;
        left: 50%;
        top: 50%;
        -webkit-transform: translate3d(-50%, -50%, 0);
        transform: translate3d(-50%, -50%, 0);
        text-align: center;
    }
    .popup_insurance_success .icon_insurance {
        display: block;
        width: 124px;
        margin: 0 auto 16px;
    }
    .popup_insurance_success .tip {
        font-size: 16px;
        color: rgb(170, 170, 170);
        display: block;
        line-height: 22px;
    }

    div.kong_div{
        height: 30px;
    }
    .tip_detail{
        font-size: 14px;
        color: #666666;
        letter-spacing: 0;
        text-align: center;
        line-height: 16px;
    }
    .padding{
        height: 108px;
        width: 100%;
        display: inline-block;
    }
    .addr_name{
        font-size: 16px;
        color: #333333;
        line-height: 24px;
        font-weight: bold;
        margin: 10px 0px 5px 0px;
        height: 24px;
    }
    .addr_detail{
        font-size: 14px;
        color: #999999;
        line-height: 20px;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
        width: 96%;
    }
    .error_tips{
        display: inline-block;
    }
    .error_text{
        height: 20px;
        font-size: 14px;
        color: #F79F8B;
        letter-spacing: 0;
        line-height: 20px;
    }
    .errorIcon{
        width: 5px;
        height: 5px;
        background-color: #F79F8B;
        display: inline-block;
        border-radius: 6px;
        margin-right: 5px;
        margin-bottom: 3px;
    }
    .relacation{ 
        width: 60px;
        font-size: 14px;
        color: #4990E2;
        letter-spacing: 0;
        line-height: 22px;
        display: inline-block;
        position: absolute;
        right: 22px;
        bottom: 0px;
    }
    .feedback-box{
        position: absolute;
        right: 12px;
        top: 16px;
    }
    .feedback-icon{
        width: 12px;
        height: 12px;
    }
    .feedback-text{
        font-size: 14px;
        height: 22px;
        color: #4990E2;
        letter-spacing: 0;
        line-height: 22px; 
    }
    .location_tip{
        margin-top: 14px;
        width: 100%;
        height: 22px;
        position: relative;
    }
</style>



